'use strict';
const { Model } = require('sequelize');

module.exports = (sequelize, DataTypes) => {
  class TechnicalDirection extends Model {}

  TechnicalDirection.init({
    title: {
      type: DataTypes.STRING(255),
      allowNull: false,
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: false,
    },
    technologies: {
      type: DataTypes.JSON, // 使用 JSON 而不是 JSONB
      allowNull: false,
    },
    price_low: {
      field: 'price_low',
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
    },
    price_high: {
      field: 'price_high',
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
    },
    createdAt: {
      field: 'created_at',
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
    },
    updatedAt: {
      field: 'updated_at',
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      onUpdate: DataTypes.NOW,
    },
  }, {
    sequelize,
    modelName: 'TechnicalDirection',
    tableName: 'technical_directions',
    timestamps: true,
  });

  return TechnicalDirection;
};